/**
 * @Auther: wangliuyang
 * @Date: 2021/4/19 22:31
 * @Description: 搜索旋转排序数组
 */
public class Solution_33 {
        public int search(int[] nums, int target) {
            if(nums == null || nums.length == 0) {
                return -1;
            }
            int start = 0;
            int end = nums.length - 1;
            int mid = 0;
            while(start <= end){
                mid = start + ((end - start) >> 2);
                if(nums[mid] == target ) {
                    return mid;
                } else if(nums[mid] >= nums[start] ){ //说明左侧有序
                    if(target < nums[mid] && target >= nums[start]){
                        end  = mid -1;
                    }else{
                        start = mid + 1;
                    }
                }else{
                    if(target > nums[mid] && target <= nums[end]){
                        start  = mid + 1;
                    }else{
                        end = mid - 1;
                    }
                }
            }
            return -1;
        }
}
